package training;

/**
 * 
 * @author harinath 02/10/2013
 * 
 *         http://www.btaz.com/java/java-primitive-data-type-sizes-for-byte-
 *         short-int-long-float-double-and-char/ test for today : implement code
 *         for the logic mentioned in
 *         http://listverse.com/2007/09/17/10-easy-arithmetic-tricks/
 */

public class ArithmeticOperations {

	// additions/subtractions/multiplications/division
	// modulo operator

	// types and their sizes

	public static void display(Class<?> type, int size, Number min, Number max) {
		System.out.printf("%-6s %-2s %-20s %s\n", type, size, min, max);
	}

	public void displayLimits() {
		System.out.printf("%s %-2s %-20s %s\n", "type", "size", "min", "max");
		display(Byte.TYPE, Byte.SIZE, Byte.MIN_VALUE, Byte.MAX_VALUE);
		display(Character.TYPE, Character.SIZE, (int) Character.MIN_VALUE,
				(int) Character.MAX_VALUE);
		display(Short.TYPE, Short.SIZE, Short.MIN_VALUE, Short.MAX_VALUE);
		display(Integer.TYPE, Integer.SIZE, Integer.MIN_VALUE,
				Integer.MAX_VALUE);
		display(Float.TYPE, Float.SIZE, Float.MIN_VALUE, Float.MAX_VALUE);
		display(Double.TYPE, Double.SIZE, Double.MIN_VALUE, Double.MAX_VALUE);
		display(Long.TYPE, Long.SIZE, Long.MIN_VALUE, Long.MAX_VALUE);
		display(Double.TYPE, Double.SIZE, Double.MIN_VALUE, Double.MAX_VALUE);

	}	
	
	public void mathOperations(){
		
		//additions
		
		int a=10;
		int b=20;
		System.out.print("addition of a, b =");
		System.out.println(a+b);
		System.out.print("substraction of a, b =");
		System.out.println(a-b);
		System.out.print("division of a, b =");
		System.out.println(a/b);
		System.out.print("multiplication of a, b =");
		System.out.println(a*b);
		

	}
	
	public void moduloDemo(){
		
		byte byteValue = (byte) 135;
		System.out.println("byteValue = " + byteValue);
		
		//int intValue = 135;
		
		System.out.println(135%127 + (-128));
		
		int a=5;
		int b=3;
		System.out.println(a/b);
		System.out.println(a%b);
		
	}

	public static void main(String[] args) {
		ArithmeticOperations operations = new ArithmeticOperations();
		operations.displayLimits();
		operations.moduloDemo();
		operations.mathOperations();
	}

}
